package com.gongjian.database;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class DatabaseFactory {

    public static SqlSession getSqlSession(boolean commit) throws IOException {
        InputStream inputStream = null;

            //1.得到数据库连接
            inputStream = Resources.getResourceAsStream("mybatis-config.xml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            //2.得到执行sql的对象
            SqlSession sqlSession = sqlSessionFactory.openSession(commit);
            return sqlSession;


    }
    public static SqlSession getSqlSession() throws IOException {
        InputStream inputStream = null;

        //1.得到数据库连接
        inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //2.得到执行sql的对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        return sqlSession;


    }
}
